package com.yegs.jindie.entity;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName Msg
 * @Description 页面统一返回
 * @Author 18318242343
 * @Date 2020/8/31 20:59
 * @Version V1.0
 */
public class Msg implements Serializable {

    private final static int SUCCESS=200;
    private final static int ERROR=500;
    private final static int BADREQUEST=404;
    // 状态码
    private int code;
    // 提示信息
    private String message;
    // 封装有效数据
    private Map<String, Object> data = new HashMap<String, Object>();


    public Msg(){

    }

    private Msg(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 调用成功返回
     * @param hashMap
     * @return
     */
    public static Msg success(HashMap<String,Object> hashMap){
        Msg msg = new Msg();
        msg.code=Msg.SUCCESS;
        msg.data = hashMap;
        return msg;
    }

    /**
     * 成功返回
     * @param k
     * @param v
     * @return
     */
    public static Msg success(String k,Object v){
        HashMap<String,Object> data = new HashMap<>();
        data.put(k,v);
        Msg msg = new Msg();
        msg.code=Msg.SUCCESS;
        msg.data = data;
        return msg;
    }

    /**
     * 调用成功返回
     * @param message
     * @return
     */
    public static Msg success(String message){
        Msg msg = new Msg();
        msg.code=Msg.SUCCESS;
        msg.message = message;
        return msg;
    }
    /**
     * 失败返回信息
     * @param message
     * @return
     */
    public static Msg error(String message){
        Msg msg = new Msg();
        msg.code=Msg.ERROR;
        msg.message = message;
        return msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}
